<?

include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

if (false) {
	init_session();

	if (empty($_SESSION['user_id'])) {
		include($_SERVER['DOCUMENT_ROOT'].'/portals/login.inc.php');
		exit;
	}
}


$sql = "SELECT portal_id,portal_id FROM `portal` WHERE status_id = 1 AND public = 'Y'";

$portals = getAssoc($sql);

$bits = array();

foreach ($portals as $id => $filter) {

	$bits[] = "(SELECT *,$id AS portal_id FROM p2.gridimage{$id}_bi WHERE status_id = 1)";
}


queryExecute($sql = "CREATE OR REPLACE VIEW gridimage_bi_merge AS ".implode(' UNION ',$bits));
	
print "DONE";